package com.eastfair.builder.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.eastfair.builder.service.BuilderReportDrawingCategoryAuditService;
import com.eastfair.builder.vo.ReportDrawingCategoryVO;
import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.home.api.ReportDrawingCategoryAuditFeign;
import com.eastfair.home.vo.ReportDrawingCategoryAuditVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 图纸分类审核 服务.
 *
 * @author dqq
 * @date 2022 /8/11
 */
@Service
@Slf4j
public class BuilderReportDrawingCategoryAuditServiceImpl implements BuilderReportDrawingCategoryAuditService {

    @Resource
    private ReportDrawingCategoryAuditFeign reportDrawingCategoryAuditFeign;

    @Override
    public List<ReportDrawingCategoryAuditVO> queryByReportSpaceId(Long reportSpaceId) {
        R<List<ReportDrawingCategoryAuditVO>> result = reportDrawingCategoryAuditFeign.queryByReportSpaceId(reportSpaceId);
        if (!result.getIsSuccess()) {
            throw BizException.wrap(result.getCode(), result.getMsg());
        }
        return result.getData();
    }

    @Override
    public List<ReportDrawingCategoryVO> listReportDrawingCategoryVOByReportSpaceId(Long reportSpaceId) {
        List<ReportDrawingCategoryAuditVO> list = queryByReportSpaceId(reportSpaceId);
        if (list == null || list.isEmpty()) {
            return Collections.emptyList();
        }
        return list
                .stream()
                .map(reportDrawingCategoryAuditVO -> BeanUtil.toBean(reportDrawingCategoryAuditVO, ReportDrawingCategoryVO.class))
                .collect(Collectors.toList());
    }
}